package com.qt.myio;

import java.io.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * @Author zsf
 * @Date 2023/9/26 0:29
 * @Version 1.0
 */
public class FileSort {

    public static void main(String[] args) throws IOException {

        /**
         * 文件内容排序
         */

        FileReader fr = new FileReader(new File("src\\main\\java\\com\\qt\\myio\\file\\a.txt"));

        int len;
        StringBuilder sb = new StringBuilder();
        while ((len = fr.read()) != -1) {
            sb.append((char)len);
        }
        fr.close();
        Integer[] res = Arrays.stream(sb.toString().split("-"))
                .map(Integer::parseInt)
                .sorted()
                .toArray(Integer[]::new);

        String s = Arrays.toString(res).replaceAll(", ", "-");
        String resutl = s.substring(1, s.length() - 1);
        FileWriter fw = new FileWriter(new File("src\\main\\java\\com\\qt\\myio\\file\\a.txt"));
        fw.write(resutl);
        fw.close();


    }

}
